home *** CD-ROM | disk | FTP | other *** search
- /****i* SOURCE_FILE/INFO
- *
- * NAME
- * TabbedMenu.js
- *
- * USAGE
- * Part of Netobjects JavaScript Library.
- *
- * COPYRIGHT
- * Copyright ⌐ 2002-2004 Website Pros, Inc.
- * All Rights Reserved.
- *
- * This is an unpublished work protected by Website Pros, Inc.
- * as a trade secret, and is not to be used or disclosed except as
- * expressly provided in a written license agreement executed by
- * you and Website Pros, Inc.
- *
- * <copyright@websitepros.com>
- *
- * NOTES
- * JavaScript code.
- *****/
- if (!IS_isModuleInitialized("IS.NOF.UI.TabbedMenu"))
- {
- /****h* NOF_JavaScript_Library/NOF.UI.TabMenuItem
- *
- * NAME
- * NOF.UI.TabMenuItem
- *
- * DESCRIPTION
- *
- * External dependencies: IS.MenuItem, NOF.MenuEvent
- ****/
-
- /**
- * TabbedMenu.TabMenuItem class constructor
- *
- * @param id, internal id
- * @param label, display label
- */
- function NOF_TabMenuItem(id, label) {
- this.__proto__ = NOF_TabMenuItem.prototype;
- this.SUPER( id, label );
-
- this.listeners = new Array();
- this.getId = function getId(){ return this.id; };
-
- /**
- Invoked when a menu item is clicked. It assumes the owner implements a
- processEvent( Event ) method and calls it.
- */
- this.onClick = function onClick() {
- this.owner.processEvent( new NOF.MenuEvent(NOF.MenuEvent.ITEM_SELECTED, this) );
- }
- }
- NOF_TabMenuItem.inherits ( IS.MenuItem )
- {
- var method = NOF_TabMenuItem.prototype;
-
- method.release = function (){
- if (this.listeners != null )
- for (var i = 0; i++; i < this.listeners.length )
- this.listeners[i] == null;
-
- this.owner = null;
- this.listeners = null;
- };
-
- /**
- Generates a qualified id for the item.
-
- @return the qualified id of the item as ownerId_itemId
- */
- method.getQualifiedId = function () {
- return this.owner.id + "_" + this.id;
- };
-
- /**
- Adds the <code>listener</code> to the listeners list
-
- @param listener
- */
- method.addListener = function ( listener ) {
- this.listeners[this.listeners.length] = listener;
- }
-
- /**
- Removes the <code>listener</code> from the listeners list
-
- @param listener
- */
- method.removeListener = function ( listener ) {
- for (var i = 0; i++; i < this.listeners.length ){
- try{
- if ( this.listeners[i] == listener ){
- this.listeners[i] = this.listeners[this.listeners.length];
- this.listeners.length--;
- }
- }catch(e){
- //wsp_tabm_logger.severe( "could not remove listener " + i );
- }
- }
- }
-
- /**
- Notifies all registered listeners of the event occured
-
- @param event, a MenuEvent object
- */
- method.notifyListeners = function ( event ) {
- for (var i = 0; i < this.listeners.length; i++ ){
- try{
- //NOF.util_logging_ConsoleLogger_global.info ( "notifying: " + event.getID());
- if (event.getID() == NOF.MenuEvent.ITEM_SELECTED )
- this.listeners[i].menuSelected( event );
- else if (event.getID() == NOF.MenuEvent.ITEM_DESELECTED )
- this.listeners[i].menuDeselected( event );
- //NOF.util_logging_ConsoleLogger_global.info ( "notification ended: " + event.getID());
- }catch(e){
- //wsp_tabm_logger.severe( "could not notify listener " + i );
- }
- }
- }
- }
-
- //NOF.__proto__.TabMenuItem = NOF_TabMenuItem; // add TabMenuItem class to NOF namespace
- NOF.UI.__proto__.TabMenuItem = NOF_TabMenuItem; // add TabMenuItem class to UI namespace
-
- /****h* NOF_JavaScript_Library/NOF.UI.TabbedMenu
- *
- * NAME
- * NOF.UI.TabbedMenu
- *
- * DESCRIPTION
- *
- * External dependencies: IS.Menu
- *
- * USAGE:
- <code>
- //create a menu instance
- var tabbedMenu = new NOF.UI.TabbedMenu("menuId", "NOF.variableName", owner);
-
- //sets the browser document to generate the menu on (via writeln method)
- tabbedMenu.document = document;
-
- //add menu items (tabs)
- var tmpItem2 = new NOF.UI.TabMenuItem ("TabId2", "TabLabel2");
-
- tabbedMenu.addItem (new NOF.UI.TabMenuItem ("TabId1", "TabLabel1") );
- tabbedMenu.addItem (tmpItem2 );
-
- tabbedMenu.selectItem( tmpItem ); //highlights the given item in the menu
- </code>
-
- NOTES:
- 1. the content is decoupled now from the menu and you have to use a listner and
- explicitely act on select/deselect events. TabbedMenuWindow provides the functionality
- 2. you should use getId() now instead of .id
-
- //TODO:
- - Add support for hooking generator functions for various parts of the menu (footer, header, etc.)
- ****/
-
- /*
- TabbedMenu class constructor
-
- @param id, internal id
- @param varName, variable name to be injected in the NOF namespace
- @param owner, the menu owner
- @param width, the width of the menu per HTML table.width
- @param height, the height of the menu per HTML table.height
- @param cellSpacing, per HTML table.cellSpacing. default is 0
- @param cellPadding, per HTML table.cellPadding. default is 0
- @param border, per HTML table.border. default is 0
- */
- function NOF_TabbedMenu( id, varName, owner, width, height, cellSpacing, cellPadding, border) {
- this.__proto__ = NOF_TabbedMenu.prototype;
- this.SUPER( id, varName, null , owner );
-
- //private interface
- this.currentItem = null;
- this.previousItem = null;
- this.document = null;
- this.width = (width != null ? width : 0);
- this.height = (height != null ? height : 0);
- this.cellSpacing = (cellSpacing != null ? cellSpacing : 0);
- this.cellPadding = (cellPadding != null ? cellPadding : 0);
- this.border = (border != null ? border : 0);
-
- this.tabSize = 112;
-
- this.IMAGES_PATH = "../resources/images/";
- }
-
- NOF_TabbedMenu.inherits( IS.Menu )
- {
- var method = NOF_TabbedMenu.prototype;
-
- method.setImagesPath = function (path) {
- this.IMAGES_PATH = path;
- }
-
- method.release = function (){
- if (this.items != null)
- {
- for ( var i=0; i< this.items.length; i++ ){
- try{
- this.items[i].release();
- }catch(e){
- }
- this.items[i] = null;
- }
- }
-
- if (this.listeners != null)
- for (var i = 0; i++; i < this.listeners.length )
- this.listeners[i] == null;
-
- this.listeners = null;
- this.document = null;
- this.items = null;
- this.owner = null;
- };
-
- method.setDocument = function ( document ) {
- if (typeof(document.getRawDoc) == 'function')
- this.document = document.getRawDoc();
- else
- this.document = document;
- };
-
- /**
- * getAfterTabsWidth
- *
- * @return the number of columns for the content are as 3 times the number of tabs + 2<br>
- * each tab is comprised of three columns left, middle and right<br>
- * next right to the tabs there are 2 additional spacing columns
- */
- method.getAfterTabsWidth = function (){
- return this.width - (this.tabSize + 4) * this.getItemCount() - 10;
- };
-
- /**
- @return the number of columns for the content are as 3 times the number of tabs + 2<br>
- each tab is comprised of three columns left, middle and right<br>
- next right to the tabs there are 2 additional spacing columns
- */
- method.getContentAreaColsNo = function (){
- return 3 * this.getItemCount() + 2;
- };
-
- /**
- Changes the source URL for the image
-
- @param imgId, the image name per HTML img.name
- @param src, the source URL
- */
- method.rollImage = function (imgId, src){
- //wsp_tabm_logger.info(imgId + " " + src);
- eval("this.document.images[ '"+ imgId +"' ].src = src;");
- };
-
- //public interface
- method.getCurrentItem = function () {return this.currentItem;};
- method.setCurrentItem = function ( item ) {this.currentItem = item;};
-
- /*getter/setter for the previously selected item*/
- method.getPreviousItem = function () {return this.previousItem;};
- method.setPreviousItem = function ( item ) {this.previousItem = item;};
-
- /**
- Adds the <code>listener</code> to the listeners list of each menu item
-
- @param listener
- */
- method.addListener = function ( listener ) {
- for ( var i=0; i< this.items.length; i++ )
- this.items[i].addListener( listener );
- };
-
- /**
- Removes the <code>listener</code> from the listeners list of each menu item
-
- @param listener
- */
- method.removeListener = function ( listener ) {
- for ( var i=0; i< this.items.length; i++ )
- this.items[i].removeListener( listener );
- };
-
- /**
- Redraws the <code>item</code> according to the <code>asSelected</code> boolean flag.
-
- @param item TabbedMenuItem
- @param asSelectected boolean
- */
- method.redrawItem = function ( item, asSelectected ) {
- if ( asSelectected ){
- this.redrawItemAsSelected( item );
- }else{
- this.redrawItemAsDeselected( item );
- }
- };
-
- /**
- Redraws the <code>item</code> by changing the appearance to a highlighted view.
-
- @param item TabbedMenuItem
- */
- method.redrawItemAsSelected = function ( item ) {
- var tabId = item.getQualifiedId();
- var document = this.document;
-
- //wsp_tabm_logger.severe( ">>>>>>>> " + tabId + "<<<<<<<<<<<" );
-
- document.all["tabText"+ tabId].className = "tabStyleHl"; //bold the tab text
-
- //display the selected state
- document.all["tab" + tabId].style.backgroundImage = "url('" + this.IMAGES_PATH + "tab-top-hi.gif')";
- document.all["tabBottom" + tabId].style.backgroundImage = "url('" + this.IMAGES_PATH + "pix.gif')";
-
- //fix the margins
- this.rollImage("tabLeft" + tabId, this.IMAGES_PATH + "tab-top-hi.gif");
- this.rollImage("tabRight" + tabId, this.IMAGES_PATH + "tab-top-hi.gif");
-
- //this is the rightPart of the previous tab
- //check if is the first tab
- var curPos = this.getItemPos( item.getId() );
- if (curPos > 0){
- var leftItem = this.items[curPos - 1];
- this.rollImage("tabRight" + leftItem.getQualifiedId(), this.IMAGES_PATH + "tab-left-hi.gif");
- }else{
- this.rollImage("tabLeftFirst" + this.id, this.IMAGES_PATH + "tab-left-hi.gif");
- }
-
- //this is the leftPart of the next tab
- //check if is the last item
- if (curPos != (this.getItemCount() - 1) ){
- var rightItem = this.items[curPos + 1];
- this.rollImage("tabLeft" + rightItem.getQualifiedId(), "" + this.IMAGES_PATH + "tab-right-hi.gif");
- }else{
- this.rollImage("tabRightLast" + this.id, "" + this.IMAGES_PATH + "tab-right-hi.gif");
- }
- }
-
-
- /**
- Reverts all menu items in a deselected state.
- */
- method.redrawAllItemsAsDeselected = function () {
- //set the deselect state for the left most margin
- this.rollImage("tabLeftFirst" + this.id, "" + this.IMAGES_PATH + "pix.gif");
-
- for (var i=0; i<this.items.length ; i++)
- this.redrawItemAsDeselected( this.items[i] );
-
- //set the deselect state for the right most margin
- this.rollImage("tabRightLast" + this.id, "" + this.IMAGES_PATH + "pix.gif");
- }
-
- /**
- Redraws the <code>item</code> by changing the appearance to a lowered view.
-
- @param item TabbedMenuItem
- */
- method.redrawItemAsDeselected = function ( item ){
- var tabId = item.getQualifiedId();
- var document = this.document;
-
- document.all["tabText" + tabId].className = "tabStyle"; //un-bold the tab text
-
- //display the normal stat
- document.all["tab" + tabId].style.backgroundImage = "url('" + this.IMAGES_PATH + "tab-top-low.gif')";
- document.all["tabBottom" + tabId].style.backgroundImage = "url('" + this.IMAGES_PATH + "tab-bottom.gif')";
-
- //fix the margins
- this.rollImage("tabLeft" + tabId, "" + this.IMAGES_PATH + "tab-left-low.gif");
- this.rollImage("tabRight" + tabId, "" + this.IMAGES_PATH + "tab-right-low.gif");
- };
-
-
- /**
- Shows the <code>item</code>.
-
- @param item TabbedMenuItem
- */
- method.showItem = function ( item ){
- var tabId = item.getQualifiedId();
- var document = this.document;
-
- document.all["tabText" + tabId].style.visibility = "visible"; //hide the tab text
-
- //display the normal stat
- document.all["tab" + tabId].style.visibility = "visible";
-
- //fix the margins
- //document.all["tabLeft" + tabId].style.visibility = "visible";
- document.all["tabRight" + tabId].style.visibility = "visible";
- };
-
- /**
- Hides the <code>item</code>.
-
- @param item TabbedMenuItem
- */
- method.hideItem = function ( item ){
- var tabId = item.getQualifiedId();
- var document = this.document;
-
- document.all["tabText" + tabId].style.visibility = "hidden"; //hide the tab text
-
- //display the normal stat
- document.all["tab" + tabId].style.visibility = "hidden";
-
- //fix the margins
- //document.all["tabLeft" + tabId].style.visibility = "hidden";
- document.all["tabRight" + tabId].style.visibility = "hidden";
- };
-
- /**
- Event handler for all MenuEvents. Currently events different than ITEM_SELECTED
- are sliently discarded.
-
- @param event NOF.MenuEvent
- */
- method.processEvent = function ( event ) {
- if (event.getID() == NOF.MenuEvent.ITEM_SELECTED ){
- this.getCurrentItem().notifyListeners( new NOF.MenuEvent(NOF.MenuEvent.ITEM_DESELECTED, this.getCurrentItem()) );
- this.onItemSelected( event.getSource() );
- this.getCurrentItem().notifyListeners( new NOF.MenuEvent(NOF.MenuEvent.ITEM_SELECTED, this.getCurrentItem()) );
- }
- };
-
- /**
- Event handler for ITEM_SELECTED events. Updates the appearance of the <code>item</code> and
- internal members previous/current item.
-
- @param TabbedMenuItem
- */
- method.onItemSelected = function ( item ) {
- if ( this.currentItem == null)
- this.currentItem = this.items[0] ;
-
- this.previousItem = this.currentItem;
- this.currentItem = item; //assume the source just menuItems for now
-
- this.redrawAllItemsAsDeselected();
- this.redrawItem( item, true );
- };
-
- /**
- See onItemSelected.
- */
- method.selectItem = method.onItemSelected;
-
- /**
- Builds the menu's header as a table opening w/ three rows.<br>
- First row contains the actual tabs for the navigation.<br>
- The second row contains the tabs underline<br>
- The third row is an opening for the content cell<br>
-
- @return The html representation of the menu's header
- */
- method.getHeader = function () {
- var menuHeader = "";
-
- menuHeader += toHTML_H ( this );
-
- //first row generating clickable tabs
- menuHeader += Item_toHTML_H ( this );
- var items = this.items;
- for (var i = 0; i < items.length; i++){
- var menuItem = items[i];
- if (menuItem.owner == null)
- { menuItem.owner = this; }
-
- menuHeader += Item_toHTML_C( menuItem );
- }
-
- menuHeader += Item_toHTML_F ( this );
-
- //second row generating tabs bottom
- menuHeader += ItemBottom_toHTML_H ( this );
- var items = this.items;
- for (var i = 0; i < items.length; i++){
- var menuItem = items[i];
- if (menuItem.owner == null)
- { menuItem.owner = this; }
-
- menuHeader += ItemBottom_toHTML_C( menuItem );
- }
-
- var btm = ItemBottom_toHTML_F ( this );
- menuHeader += btm;
- return menuHeader;
- }
-
- /*
- In the future the entire menu could be generated as opposed to a static html for the content.<br>
- Not really useful at this moment as it lacks the ability to hook a content generator.<br>
- getHeader and getFooter generate the dialog's frame.
-
- @return The html representation of the menu's header
- */
- method.toHTML = function (){
- var document = this.document;
-
- document.write ( this.getHeader() );
- document.write ( this.getContent() );
- document.write ( this.getFooter() );
- };
-
-
- /**
- In the future the menu's content could be generated instead of a static html.<br>
- getHeader and getFooter generate the dialog's frame.
-
- @return the initial content.
- */
- method.getContent = function (){ return toHTML_C( this ); }
-
- /*
- Builds the menu's footer by closing the content cell/row and menu's table<br>
-
- @return The html representation of the menu's header
- */
- method.getFooter = function (){ return toHTML_F ( this );}
-
- //
- // Menu and MenuItem Definition
- //
- function toHTML_H (menu) {
- return "<!--PropertyPage-->\n" +
- "<table cellpadding=\"" + menu.cellPadding + "\" cellspacing=\""+ menu.cellSpacing +
- "\" border=\""+ menu.border +"\" width=\""+ menu.width + "\" height=\"" + menu.height + "\">\n";
- }
-
- function toHTML_C ( menu ) {
- return "Dialog Content";
- }
-
- function Item_toHTML_H ( menu ) {
- return "<tr height=20>\n"+
- "\t<td width=2 border=0><img width=\"2\" height=20 alt=\"\" src=\"" + menu.IMAGES_PATH + "tab-left-hi.gif\" name=tabLeftFirst" + menu.id + "></td>"+
- "\t<td rowspan=\"2\"><table cellspacing=0 cellpadding=0><tr>";
- }
-
- function Item_toHTML_C (item, target, href) {
- var itemView =
- "\t<td width=\"2\"><IMG width=2 border=0 height=20 alt=\"\" src=\"" + item.owner.IMAGES_PATH + "tab-left-low.gif\" " +
- "name=\"tabLeft" + item.getQualifiedId() + "\" ></td>\n" +
- "\t<td id=\"tab" + item.getQualifiedId() + "\" onClick=\"" + item.owner.varName + ".getItem(\'" + item.getId() + "\').onClick();\"" +
- "align=\"middle\" style=\"BACKGROUND-POSITION: 50% top; BACKGROUND-IMAGE: url(" + item.owner.IMAGES_PATH + "tab-top-low.gif); CURSOR: pointer; BACKGROUND-REPEAT: repeat-x\" width=\"" + item.owner.tabSize + "\">" +
- "\t <nobr id=\"tabText" + item.getQualifiedId() + "\" class=\"tabStyle\"> " + item.label + " </nobr></td>\n" +
- "\t<td width=\"2\"><IMG height=20 alt=\"\" src=\"" + item.owner.IMAGES_PATH + "tab-right-low.gif\" width=2 border=0 " +
- "name=\"tabRight" + item.getQualifiedId() + "\" ></td>\n";
-
- return itemView;
- }
-
- function Item_toHTML_F ( menu ) {
- return "<td width=6><img width=2 border=0 height=20 alt=\"\" src=\"" + menu.IMAGES_PATH + "pix.gif\" name=tabRightLast"+ menu.id +"></td>"+
- "<td width=2><img width=1 border=0 height=1 alt=\"\" src=\"" + menu.IMAGES_PATH + "pix.gif\"></td></tr>";
- }
-
-
- function ItemBottom_toHTML_H ( menu ){
- return "<tr height=2>";
- }
-
- function ItemBottom_toHTML_C ( item ){
- return "\t<td width=\"" + (item.owner.tabSize + 4) + "\" background=\"" + item.owner.IMAGES_PATH + "tab-bottom.gif\" colspan=\"3\" " +
- "id=\"tabBottom" + item.getQualifiedId() + "\"><img width=\""+ (item.owner.tabSize + 4) + "\" border=0 height=2 alt=\"\" src=\"" + item.owner.IMAGES_PATH + "pix.gif\"></td>\n";
-
- }
-
- function ItemBottom_toHTML_F ( menu ){
- return " <TD background=" +menu.IMAGES_PATH + "tab-bottom.gif><IMG height=2 alt=\"\" src=\"" +menu.IMAGES_PATH + "pix.gif\" width=1 border=0></TD>" +
- " <TD width=\"100%\" background=" +menu.IMAGES_PATH + "tab-bottom.gif><IMG height=2 alt=\"\" src=\"" +menu.IMAGES_PATH + "tab-bottom.gif\" width=2 border=0></TD>" +
- " </TR>" +
- " </TABLE>" +
- " " +
- " </TD>" +
- " <TD width=\"" + menu.getAfterTabsWidth() + "\"><IMG height=1 alt=\"\" src=\"" +menu.IMAGES_PATH + "pix.gif\" width=\"" + menu.getAfterTabsWidth() + "\" border=0></TD>" +
- " <TD width=2><IMG height=1 alt=\"\" src=\"" +menu.IMAGES_PATH + "pix.gif\" width=1 border=0></TD>" +
- "</TR>" +
- "<TR height=2>" +
- " <TD id=tabBottomFirst width=2 background=" +menu.IMAGES_PATH + "tab-bottom.gif><IMG height=2 alt=\"\" src=\"" +menu.IMAGES_PATH + "pix.gif\" width=1 border=0></TD><!--TabsBottomLine-->" +
- " <TD background=" +menu.IMAGES_PATH + "tab-bottom.gif><IMG height=1 alt=\"\" src=\"" +menu.IMAGES_PATH + "pix.gif\" width=1 border=0></TD>" +
- " <TD width=2><IMG height=2 alt=\"\" src=\"" +menu.IMAGES_PATH + "tab-border-top-right.gif\" width=2 border=0></TD>" +
- "</TR>" +
- "<TR>" +
- "<TD width=2 background=" +menu.IMAGES_PATH + "tab-border-left.gif><IMG height=1 alt=\"\" src=\"" +menu.IMAGES_PATH + "pix.gif\" width=1 border=0></TD><!--PropertyPageContent-->" +
- "<TD style=\"PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; PADDING-TOP: 5px\" vAlign=top width=\"100%\" colSpan=2>";
- }
-
-
- function toHTML_F ( menu ) {
- return "\t</td>\n<!--/PropertyPageContent-->\n" +
- "\t<td background=\"" +menu.IMAGES_PATH + "tab-border-right.gif\" width=\"2\"><img height=1 alt=\"\" src=\"" +menu.IMAGES_PATH + "pix.gif\" width=1 border=0></td>\n" +
- "</tr>\n<!--/DialogContentRow-->\n" +
- "<!--BottomBorder-->\n" +
-
- "<tr height=\"2\">\n"+
- "\t<td width=\"2\"><img height=2 alt=\"\" src=\"" +menu.IMAGES_PATH + "tab-border-bottom-left.gif\" width=\"2\" border=\"0\"></td>\n" +
- "\t<td colspan=\"2\" background=\"" +menu.IMAGES_PATH + "tab-border-bottom.gif\"><img height=1 alt=\"\" src=\"" +menu.IMAGES_PATH + "pix.gif\" width=1 border=0></td>\n" +
- "\t<td width=\"2\"><img height=2 alt=\"\" src=\"" +menu.IMAGES_PATH + "tab-border-bottom-right.gif\" width=\"2\" border=\"0\"></td>\n" +
- "</tr>\n" +
- "<!--/BottomBorder-->\n" +
- "</table>\n" +
- "<!--/PropertyPage-->\n";
- }
- }
-
- //NOF.__proto__.TabbedMenu = NOF_TabbedMenu; //add TabMenu class to NOF namespace
- NOF.UI.__proto__.TabbedMenu = NOF_TabbedMenu; //add TabMenu class to UI namespace
- }